<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jq.js"></script>
    <style>
        li{
            list-style: none;
            float: left;
        }
        .li1{
            width: 300px;
            height: 300px;
            border: 1px solid #E4E4E4;
        }
        .li2{
            width: 400px;
            height: 300px;
            margin-left: 20px;
        }
        .jiaqian{
            width: 100%;
            height: 50px;
            background-color: #F2F2F2;
            line-height: 50px;
        }
        .jiaqan span{
            padding-left: 20px;
            color: red;
        }
        .pinpai{
            width: 100%;
            height: 40px;
            line-height: 40px;
        }
        .pinpai span,.peisong span{
            padding-left: 50px;
        }
        .peisong{
            border-bottom: 1px dotted #DCDCDC;
            padding-bottom:20px ;
        }
        .shu{
            padding-left: 50px;
        }
        .jian,.jia{
           width: 20px;
           height: 20px;
           
       }
       .car{
           width: 200px;
           height: 30px;
           color: red;
           border-radius: 5px;
           background-color: white;
           border: 1px solid red;
           margin-left: 100px;
           
       }
       .botton{
           width: 100%;
           height: 60px;
           line-height: 60px;
       }
       .botton span{
           display: inline-block;
           width: 30px;
           height: 10px;
           text-align: center;
       }
       .kucun{
           border-bottom: 1px dotted #DCDCDC;
           margin-top: 10px;
       }
    </style>
</head>
<body>
    <ul>
       
    </ul>
</body>
<script src="./data.js"></script>
<script>
    $(function(){
        var li1=$('<li class="li1">'+'<img src=http:'+data[0].image+'>'+'</li>');
        $('ul').append(li1);
        var li2=$('<li class="li2">'+
            '<h3>'+data[0].name+'</h3>'+
            '<div class="jiaqan">'+data[0].categoryName+':'+'<span>'+'￥'+data[0].price+'</span>'+'</div>'+
            '<div class="pinpai">'+'品  牌:'+'<span>'+data[0].brandName+'</span>'+'</div>'+
            '<div class="peisong">'+'配  送:'+'<span>'+'从杭州市到浙江省 快递： 5.00元'+'</span>'+'</div>'+
            '<div class="kucun">'+
                '库  存:'+'<span class="shu">'+data[0].stock+'件'+'</span>'+'<br>'+
                '<div class="botton">'+
                '<button class="jian">'+'-'+'</button>'+'<span>'+'1'+'</span>'+'<button class="jia">'+'+'+'</button>'+
                '<button class="car">'+'加入购物车'+'</button>'
                +'</div>'
                +'</div>'

            +'</li>')
        $('ul').append(li2);
        $('.car').click(function(){
            $(location).attr('href','./购物车.html');
            localStorage.setItem('name',data[0].categoryName);
            localStorage.setItem('price',data[0].price);
            localStorage.setItem('number',$(this).siblings('span').text());
        })  
        $('.car').mouseover(function(){
            $(this).css('cursor','pointer');
        })
        $('.jia').click(function(){
           var num =($(this).siblings('span').text())*1; 
        //    console.log(num);
           num++;
           $(this).siblings('span').text(num);
        })
        $('.jian').click(function(){
            var num = parseInt($(this).siblings('span').text());
            if(num > 0){
                num--;
            // console.log(num);
            $(this).siblings('span').text(num);
            }   
        })
    })
</script>
</html>